#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#include <memory>

#include "GSystem.h"

namespace GUtil
{
	void* GSystem::GetInstance(const char* Name)
	{
		return GetModuleHandle(Name);
	}

	GSize GSystem::GetCacheLineSize()
	{
	    GSize CacheLineSize = 0;
		SYSTEM_LOGICAL_PROCESSOR_INFORMATION* Buffer = 0;

		DWORD buffer_size = 0;
		GetLogicalProcessorInformation(0, &buffer_size);
		Buffer = (SYSTEM_LOGICAL_PROCESSOR_INFORMATION*)malloc(buffer_size);

		GetLogicalProcessorInformation(Buffer, &buffer_size);

		for (GSize I = 0; I != buffer_size / sizeof(SYSTEM_LOGICAL_PROCESSOR_INFORMATION); ++I) 
		{	
			if (Buffer[I].Relationship == RelationCache && Buffer[I].Cache.Level == 1) 
			{
				CacheLineSize = Buffer[I].Cache.LineSize;
				break;
			}
		}

		free(Buffer);
		return CacheLineSize;
	}

	GUInt32	GSystem::GetCoreCount()
	{
		SYSTEM_INFO SystemInfo;
		GetSystemInfo(&SystemInfo);

		return SystemInfo.dwNumberOfProcessors;
	}

	//! Hardcoded for now
	GSSEVersion	GSystem::GetSSEVersion()
	{
		return G_SSE_VER_4;
	}

}